package com.project.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

/**
 * 文件上传控制器
 */
@RestController
public class UploadController {
    @RequestMapping("upload")
    public String upload(@RequestParam("uploadImg") MultipartFile mf) throws IOException {
        //得到上传文件的名称
    var fileName=mf.getOriginalFilename();
    //以时间毫秒数重命名上传文件，防止因上传文件同名而导致的覆盖
    fileName=System.currentTimeMillis()+fileName.substring(fileName.lastIndexOf("."));
    mf.transferTo(new File("D:/java/JAVA-Two/chapter5/JavaWeb/stageFirst/stuFaceImg/"+fileName));

    return fileName;
    }
}
